package persentation.presentUniversityDean;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import businesslogic.chooseCourseBl.ChooseCourseController;
import businesslogic.courseBl.CourseController;
import businesslogic.frameworkBl.FrameworkController;
import businesslogic.teachPlanBl.TeachPlanController;
import businesslogic.userBl.StudentController;
import businesslogic.userBl.UniversityDeanController;

import javax.swing.SwingConstants;

import vo.chooseCourseVO.ChooseCourseVO;

public class ButtonPanel extends JPanel {
	private static Image BOTTOM = new ImageIcon("Graphics/universityDean/UDeanbottom.png")
			.getImage();
	private static ImageIcon TEACHPLAN = new ImageIcon(
			"Graphics/universityDean/showScore2.png");
	private static ImageIcon CHANGE_PASSWRORD = new ImageIcon(
			"Graphics/universityDean/changePassword.png");
	private static ImageIcon STUDENT = new ImageIcon("Graphics/universityDean/student.png");
	private static ImageIcon TEACHER = new ImageIcon("Graphics/universityDean/teacher.png");
	private static ImageIcon FRAMEWORK = new ImageIcon(
			"Graphics/universityDean/deleteCourse.png");
	private static ImageIcon SHENGHE = new ImageIcon("Graphics/universityDean/shenghe.png");
	private MyTabbedPane tabbedPane;
	private FrameworkPanel frameworkPanel;
	private TeacherInfoPanel teacherInfoPanel;
	private StudentInfoPanel studentInfoPanel;
	private DepartmentInfoPanel departmentInfoPanel;
	private ChangePasswordPanel changePasswordPanel;
	private ShenghexuankePanel shenghexuankePanel;
	private UniversityDeanController uDeanController;
	private TeachPlanController teachPlanController;
	private FrameworkController frameworkController;
	private ChooseCourseController chooseCourseController;
	private BottomPanel bottomPanel;
	private ArrayList<ChooseCourseVO> chooseCourseVOs;
	/**
	 * Create the panel.
	 */
	public ButtonPanel(final MyTabbedPane tabbedPane, String uDeanID) {

		teachPlanController = new TeachPlanController();
		uDeanController = new UniversityDeanController(uDeanID);
		frameworkController = new FrameworkController();
		chooseCourseController = new ChooseCourseController(uDeanID);
		try {
			System.out.println("|||||||||||||||||||||||||||||||||||||||||||||||||");
			chooseCourseVOs = chooseCourseController.getAllStudentChoose();
			System.out.print("|||||||||||||||||||||||||||||||||||||||||||||||||");
		} catch (Exception e1) {
			// TODO 自动生成的 catch 块
			e1.printStackTrace();
		}
		frameworkPanel = new FrameworkPanel(frameworkController);
		changePasswordPanel = new ChangePasswordPanel(uDeanController);
		teacherInfoPanel = new TeacherInfoPanel(uDeanController);
		studentInfoPanel = new StudentInfoPanel(uDeanController);
		departmentInfoPanel = new DepartmentInfoPanel(teachPlanController);
		bottomPanel = new BottomPanel(uDeanController);
		shenghexuankePanel = new ShenghexuankePanel(uDeanController);
		
		tabbedPane.addBottom(bottomPanel);
		
		setSize(213, 589);
		this.tabbedPane = tabbedPane;
		setLayout(null);
		tabbedPane.addOne("欢迎使用", bottomPanel);

		JButton button_3 = new JButton("修改密码");
		button_3.setHorizontalAlignment(SwingConstants.LEFT);
		button_3.setIcon(CHANGE_PASSWRORD);
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.addOne("修改密码", changePasswordPanel);
			}
		});
		button_3.setBounds(14, 387, 175, 61);
		add(button_3);
		button_3.setFont(new Font("微软雅黑", Font.BOLD, 16));

		JButton btnNewButton = new JButton("框架策略");
		btnNewButton.setHorizontalAlignment(SwingConstants.LEFT);
		btnNewButton.setIcon(FRAMEWORK);
		btnNewButton.setBounds(14, 22, 173, 61);
		add(btnNewButton);
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frameworkPanel.setMyTabbedPane(tabbedPane);
				tabbedPane.addOne("整体教学框架策略", frameworkPanel);
			}
		});
		btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 16));

		JButton button_2 = new JButton("教师统计信息");
		button_2.setIcon(TEACHER);
		button_2.setHorizontalAlignment(SwingConstants.LEFT);
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.addOne("教师统计信息", teacherInfoPanel);
			}
		});
		button_2.setFont(new Font("微软雅黑", Font.BOLD, 16));
		button_2.setBounds(14, 168, 175, 61);
		add(button_2);

		JButton button_4 = new JButton("学生统计信息");

		button_4.setHorizontalAlignment(SwingConstants.LEFT);
		button_4.setIcon(STUDENT);
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				studentInfoPanel.setMyTabbedPane(tabbedPane);
				tabbedPane.addOne("学生统计信息", studentInfoPanel);
			}
		});
		button_4.setFont(new Font("微软雅黑", Font.BOLD, 16));
		button_4.setBounds(14, 241, 175, 61);
		add(button_4);

		JButton button = new JButton("院系教学计划");
		button.setHorizontalAlignment(SwingConstants.LEFT);
		button.setIcon(TEACHPLAN);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				departmentInfoPanel.setMyTabbedPane(tabbedPane);
				tabbedPane.addOne("院系教学计划", departmentInfoPanel);
			}
		});
		button.setFont(new Font("微软雅黑", Font.BOLD, 16));
		button.setBounds(14, 314, 175, 61);
		add(button);

		JButton button_1 = new JButton("审核选课");
		button_1.setHorizontalAlignment(SwingConstants.LEFT);
		button_1.setIcon(SHENGHE);
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					System.out.println("|||||||||||||||||||||||||||||||||||||||||||||||||");
					chooseCourseVOs = chooseCourseController.getAllStudentChoose();
					System.out.print("|||||||||||||||||||||||||||||||||||||||||||||||||");
				} catch (Exception e1) {
					// TODO 自动生成的 catch 块
					e1.printStackTrace();
				}
				if(chooseCourseVOs.size()!=0){	
				shenghexuankePanel.setMyTabbedPane(tabbedPane);
				tabbedPane.addOne("审核选课", shenghexuankePanel);
			}else{
				JOptionPane.showMessageDialog(null,"已完成审核","南京大学选课系统",JOptionPane.INFORMATION_MESSAGE);
				shenghexuankePanel.setMyTabbedPane(tabbedPane);
				tabbedPane.addOne("审核选课", shenghexuankePanel);
			}
			}
		});
		button_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
		button_1.setBounds(12, 95, 175, 61);
		add(button_1);

		/*this.tabbedPane.addCloseListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (e.getActionCommand().equals("ON_TAB_CLOSE")) {
					int index = tabbedPane.getSelectedIndex();
					tabbedPane.removeTabAt(index);
					tabbedPane.removeOne(index);
					if (tabbedPane.getTabCount() == 0) {
						tabbedPane.addOne("欢迎使用", bottomPanel);
					}

				}
			}
		});*/
		this.tabbedPane.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent arg0) {
				if (tabbedPane.getSelectedComponent() == frameworkPanel) {
					frameworkPanel.fillTable();
				}

			}

		});

		/*
		 * JLabel label=new JLabel(); this.setBounds(0, 0, 200, 600);
		 * label.setIcon(BOTTOM); this.add(label);
		 */

	}

	@Override
	public void paintComponent(Graphics g) {
		g.drawImage(BOTTOM, 0, 0, null);
	}
}
